<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Open a connection to a CUBRID Server</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.cubrid-connect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">cubrid_connect</h1>
  <p class="verinfo">(PECL CUBRID &gt;= 8.3.1)</p><p class="refpurpose"><span class="refname">cubrid_connect</span> &mdash; <span class="dc-title">Open a connection to a CUBRID Server</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.cubrid-connect-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>cubrid_connect</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$host</code></span>  
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$port</code></span>  
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$dbname</code></span>  
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$userid</code></span>  
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$passwd</code></span>  
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$new_link</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span>  
  ]]] ) : <span class="type">resource</span></div>

  <p class="para rdfs-comment">
    The <span class="function"><strong>cubrid_connect()</strong></span> function is used to establish the
    environment for connecting to your server by using your server address,
    port number, database name, user name, and password. If the user name and
    password is not given, then the &quot;PUBLIC&quot; connection will be made by
    default. 
  </p>
 </div>


  <div class="refsect1 parameters" id="refsect1-function.cubrid-connect-parameters">
 <h3 class="title">参数</h3>
 <p class="para">
  <dl>

   
    <dt>
<code class="parameter">host</code></dt>

    <dd>
<p class="para">Host name or IP address of CUBRID CAS server.</p></dd>

   
   
    <dt>
<code class="parameter">port</code></dt>

    <dd>
<p class="para">Port number of CUBRID CAS server (BROKER_PORT configured in $CUBRID/conf/cubrid_broker.conf).</p></dd>

   
   
    <dt>
<code class="parameter">dbname</code></dt>

    <dd>
<p class="para">Name of database.</p></dd>

   
   
    <dt>
<code class="parameter">userid</code></dt>

    <dd>
<p class="para">User name for the database. If not given, the default
      value is &quot;public&quot;.</p></dd>

   
   
    <dt>
<code class="parameter">passwd</code></dt>

    <dd>
<p class="para">User password. If not given, the default value is &quot;&quot;.</p></dd>

   
   
    <dt>
<code class="parameter">new_link</code></dt>

    <dd>
<p class="para">If a second call is made to
      <span class="function"><strong>cubrid_connect()</strong></span> with the same arguments, no new
      connection will be established, but instead, the connection identifier
      of the already opened connection will be returned. The
      <code class="parameter">new_link</code> parameter modifies this behavior and
      makes <span class="function"><strong>cubrid_connect()</strong></span> always open a new connection,
      even if <span class="function"><strong>cubrid_connect()</strong></span> was called before with the
      same parameters.</p></dd>

   
  </dl>

  </p>
 </div>


  <div class="refsect1 returnvalues" id="refsect1-function.cubrid-connect-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    Connection identifier, when process is successful. 
  </p>
    <p class="para">
    <strong><code>FALSE</code></strong>, when process is unsuccessful.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.cubrid-connect-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1100">
   <p><strong>Example #1 <span class="function"><strong>cubrid_connect()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-30s&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"CUBRID&nbsp;PHP&nbsp;Version:"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">cubrid_version</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">33000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"demodb"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"dba"</span><span style="color: #007700">);<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;die(</span><span style="color: #DD0000">'Connect&nbsp;Error&nbsp;('</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">cubrid_error_code</span><span style="color: #007700">()&nbsp;.</span><span style="color: #DD0000">')'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">cubrid_error_msg</span><span style="color: #007700">());<br />}<br /><br /></span><span style="color: #0000BB">$db_params&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_get_db_parameter</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /><br />while&nbsp;(list(</span><span style="color: #0000BB">$param_name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$param_value</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">each</span><span style="color: #007700">(</span><span style="color: #0000BB">$db_params</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-30s&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$param_name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$param_value</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$server_info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_get_server_info</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$client_info&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_get_client_info</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-30s&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Server&nbsp;Info:"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$server_info</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-30s&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"Client&nbsp;Info:"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$client_info</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$charset&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">cubrid_get_charset</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%-30s&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"CUBRID&nbsp;Charset:"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$charset</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">cubrid_disconnect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
   </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
CUBRID PHP Version:            9.1.0.0001

PARAM_ISOLATION_LEVEL          3
LOCK_TIMEOUT                   -1
MAX_STRING_LENGTH              1073741823
PARAM_AUTO_COMMIT              1

Server Info:                   9.1.0.0212
Client Info:                   9.1.0

CUBRID Charset:                iso8859-1
</pre></div>
   </div>
  </div>
 </div>

 
   <div class="refsect1 seealso" id="refsect1-function.cubrid-connect-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
   <li class="member"><span class="function"><a href="cubrid_pconnect.html" class="function" rel="rdfs-seeAlso">cubrid_pconnect()</a> - Open a persistent connection to a CUBRID server</span></li>
   <li class="member"><span class="function"><a href="cubrid_connect_with_url.html" class="function" rel="rdfs-seeAlso">cubrid_connect_with_url()</a> - Establish the environment for connecting to CUBRID server</span></li>
   <li class="member"><span class="function"><a href="cubrid_pconnect_with_url.html" class="function" rel="rdfs-seeAlso">cubrid_pconnect_with_url()</a> - Open a persistent connection to CUBRID server</span></li>
   <li class="member"><span class="function"><a href="cubrid_disconnect.html" class="function" rel="rdfs-seeAlso">cubrid_disconnect()</a> - Close a database connection</span></li>
   <li class="member"><span class="function"><a href="cubrid_close.html" class="function" rel="rdfs-seeAlso">cubrid_close()</a> - Close CUBRID connection</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>